import com.chuangjiangx.member.basic.dao.model.InMember;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.util.DefaultUriTemplateHandler;
import org.springframework.web.util.UriUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Base64;

/**
 * @author cj-ch
 * @date 2018/1/5 上午10:39
 */
public class t2 {
    private static String wxThirdPartyAuthUrlTemplate = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={APPID}&redirect_uri={REDIRECT_URI}&response_type=code&scope={SCOPE}&state={STATE}&component_appid={COMPONENT_APPID}#wechat_redirect";
    public static void main(String[] args) throws UnsupportedEncodingException, JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);


        InMember member = new InMember();
        member.setName("张三");
        member.setMobile("13323232323");
        System.out.println(objectMapper.writeValueAsString(member));

        String urlReplace = "REDIRECT_URL_REPLACE";
        String redirectUrl = "http://member.merchant.chuangjiangx.com/api/card/consumer?merchantId=171&encrypt_code=uubAdn8jJVwCwWA2gEfqamUwg+defurVMNP32L566Ec=&card_id=pT5gr0fR9jxSBVWKWjVcq0QzB4sM";
        DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
        String authUrl = handler.expand(
                wxThirdPartyAuthUrlTemplate,
                "wx112e470dca6e16f0",
                urlReplace
                ,
                "snsapi_base",
                "",
                "wxe86dbf4d1226056d"
        ).toString();
        try {
            authUrl = StringUtils.replace(authUrl,urlReplace,UriUtils.encode(redirectUrl,"utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(authUrl);

        String encode_code = "uubAdn8jJVwCwWA2gEfqamUwg+defurVMNP32L566Ec=";
        String encode = java.net.URLEncoder.encode(encode_code, "utf-8");
        System.out.println(encode);
        System.out.println(URLDecoder.decode(encode,"utf-8"));
        System.out.println(Base64.getEncoder().encodeToString(encode_code.getBytes("utf-8")));
    }
}
